<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.3.0: http://docutils.sourceforge.net/" />
<title>vb2Py - Form Modules</title>
<link rel="stylesheet" href="default.css" type="text/css" />
</head>
<body>
<div class="document" id="vb2py-form-modules">
<h1 class="title">vb2Py - Form Modules</h1>
<!-- filename: c:\development\python22\lib\site-packages\vb2py\doc/formmodules.htm -->
<p>Contents of this page:</p>
<ul class="simple">
<li><a class="reference" href="#general">General</a></li>
<li><a class="reference" href="#default-conversion">Default Conversion</a></li>
<li><a class="reference" href="#list-of-options">List of Options</a></li>
</ul>
<p>Options:</p>
<ul class="simple">
<li><a class="reference" href="#usenewstyleclasses">UseNewStyleClasses</a></li>
<li><a class="reference" href="#respectprivatestatus">RespectPrivateStatus</a></li>
<li><a class="reference" href="#privatedataprefix">PrivateDataPrefix</a></li>
<li><a class="reference" href="#trytoextractdocstrings">TryToExtractDocStrings</a></li>
</ul>
<div class="section" id="general">
<h1><a name="general">General</a></h1>
<p>Form modules are translated into Python code modules with a single class whose name is the nane of the VB form. By default, this class is a <em>new style</em> Python class (inherits from <tt class="literal"><span class="pre">Object</span></tt>). All methods in the class are converted to unbound methods of the class. Properties are converted to Python properties but an error is raised if the property has both <tt class="literal"><span class="pre">Let</span></tt> and <tt class="literal"><span class="pre">Set</span></tt> decorators. Since Python has no equivalent of the <tt class="literal"><span class="pre">Set</span></tt> keyword, the <tt class="literal"><span class="pre">Property</span> <span class="pre">Set</span></tt> method is treated in the same way as a <tt class="literal"><span class="pre">Property</span> <span class="pre">Let</span></tt>.</p>
<p>Attributes defined at the form level are assumed to be class attributes in the Python class. By default, the conversion respects the Public/Private scope of both attributes and methods but this can be disabled if desired.</p>
</div>
<div class="section" id="default-conversion">
<h1><a name="default-conversion">Default Conversion</a></h1>
<p>VB(VBFormModule):</p>
<pre class="literal-block">
Public Name As String
Public Age As Single
Private ID As Long

Public Sub checkAge()
    If Age = 0 Then Age = 1
End Sub
'
Private Sub setUp()
    ID = Rnd()
    If ID = 0 Then setUp
End Sub
</pre>
</div>
<div class="section" id="list-of-options">
<h1><a name="list-of-options">List of Options</a></h1>
<p>Here are the options in the INI file:</p>
<pre class="literal-block">
[Classes]
# Yes or No, whether to use new style classes for all classes
UseNewStyleClasses = Yes
</pre>
<p>In addition to these specific options, some <tt class="literal"><span class="pre">General</span></tt> options apply:</p>
<pre class="literal-block">
[General]
# Yes or No, whether to respect Private status of variables
RespectPrivateStatus = Yes
# Prefix to use to tag data as private (Python normally uses __ but VB convention is m)
PrivateDataPrefix = __
    # Yes or No, whether to try to automatically extract docstrings from the code
    TryToExtractDocStrings = Yes
</pre>
<div class="section" id="usenewstyleclasses">
<h2><a name="usenewstyleclasses">UseNewStyleClasses</a></h2>
<p>By default, all forms are created as <em>new style</em> Python classes (inheriting from <tt class="literal"><span class="pre">Object</span></tt>). Old style classes can be created by setting the <tt class="literal"><span class="pre">UseNewStyleClasses</span></tt> option to <tt class="literal"><span class="pre">No</span></tt>.</p>
<p>VB(VBFormModule):</p>
<pre class="literal-block">
' VB2PY-GlobalSet: Classes.UseNewStyleClasses = No
Public Name As String
Public Age As Single
Private ID As Long

Public Sub checkAge()
    If Age = 0 Then Age = 1
End Sub
'
Private Sub setUp()
    ID = Rnd()
    If ID = 0 Then setUp
End Sub
' VB2PY-Unset: Classes.UseNewStyleClasses 
</pre>
</div>
<div class="section" id="respectprivatestatus">
<h2><a name="respectprivatestatus">RespectPrivateStatus</a></h2>
<p>Syntax: <tt class="literal"><span class="pre">RespectPrivateStatus</span> <span class="pre">=</span> <span class="pre">Yes</span> <span class="pre">|</span> <span class="pre">No</span></tt></p>
<p>By default, variables or methods defined as Private (which is the default in VB), will be marked as private in the Python module also. Private Python variables will be prefixed with a private marker (two underscores by default). Since <tt class="literal"><span class="pre">Private</span></tt> is the default in VB, this can lead to a lot of hidden variables in the Python code. The <tt class="literal"><span class="pre">RespectPrivateStatus</span></tt> option allows you to turn off the <tt class="literal"><span class="pre">Private/Public</span></tt> switch.</p>
<p>VB(VBFormModule):</p>
<pre class="literal-block">
' VB2PY-GlobalSet: General.RespectPrivateStatus = No
Public Name As String
Public Age As Single
Private ID As Long

Public Sub checkAge()
    If Age = 0 Then Age = 1
End Sub
'
Private Sub setUp()
    ID = Rnd()
    If ID = 0 Then setUp
End Sub
' VB2PY-Unset: General.RespectPrivateStatus
</pre>
</div>
<div class="section" id="privatedataprefix">
<h2><a name="privatedataprefix">PrivateDataPrefix</a></h2>
<p>Syntax: <tt class="literal"><span class="pre">PrivateDataPrefix</span> <span class="pre">=</span> <span class="pre">prefix</span></tt></p>
<p>If <tt class="literal"><span class="pre">RespectPrivateStatus</span></tt> is set then each <tt class="literal"><span class="pre">Private</span></tt> variable will be prefixed with the string specified by the <tt class="literal"><span class="pre">PrivateDataPrefix</span></tt> option. By default this is two underscores, <tt class="literal"><span class="pre">__</span></tt>, which means that Python will use <em>name mangling</em> to ensure that the names really are private. Changing this option allows names to converted to some other convention (eg <tt class="literal"><span class="pre">m</span></tt>) which marks names but does not enforce privacy.</p>
<p>VB(VBFormModule):</p>
<pre class="literal-block">
' VB2PYGlobal-Set: General.PrivateDataPrefix = m
Public Name As String
Public Age As Single
Private ID As Long

Public Sub checkAge()
    If Age = 0 Then Age = 1
End Sub
'
Private Sub setUp()
    ID = Rnd()
    If ID = 0 Then setUp
End Sub
</pre>
</div>
<div class="section" id="trytoextractdocstrings">
<h2><a name="trytoextractdocstrings">TryToExtractDocStrings</a></h2>
<p>Syntax: <tt class="literal"><span class="pre">TryToExtractDocStrings</span> <span class="pre">=</span> <span class="pre">Yes</span> <span class="pre">|</span> <span class="pre">No</span></tt></p>
<p>If <tt class="literal"><span class="pre">TryToExtractDocStrings</span></tt> is set then any contiguous block of comment lines found at the start of the module are interpretted as a docstring and added to the class definition. The docstring terminates with the first non-comment line.</p>
<p>VB(VBFormModule):</p>
<pre class="literal-block">
' VB2PY-GlobalSet: General.TryToExtractDocStrings = Yes
    ' This is the documentation for the module
    ' This line is also documentation
    ' So is this one
    ' And this is the last

Public Name As String
Public Age As Single
Private ID As Long

Public Sub checkAge()
    If Age = 0 Then Age = 1
End Sub
'
Private Sub setUp()
    ID = Rnd()
    If ID = 0 Then setUp
End Sub
' VB2PY-Unset: General.TryToExtractDocStrings
</pre>
</div>
</div>
</div>
</body>
</html>
